package com.zy.consumer.controller;

import com.zy.consumer.client.StockClient;
import com.zy.consumer.domain.Orders;
import com.zy.consumer.service.OrdersService;
import io.seata.spring.annotation.GlobalTransactional;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @author 这是那头猪？
 * @version 1.0
 * @description:
 * @date 2023/10/13 10:06
 */
@Api(tags = "首页模块")
@RestController
public class IndexController {
    @Resource
    OrdersService ordersService;

    @Resource
    StockClient stockClient;


    @GlobalTransactional
    @ApiOperation(value = "下单")
    @GetMapping("/setOrder")
    public ResponseEntity<String> sayHi(){
        //库存减1
        stockClient.setStock();

        System.out.println(1/0);

        Orders orders = new Orders();
        orders.setOrderTime(new Date());
        orders.setAmount(100);
        orders.setProductId(1);
        //订单加1
        ordersService.save(orders);
        return ResponseEntity.ok("下单成功");
    }

}